package org.diffgenova;

import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class ListRifiutiAdapter extends SimpleCursorAdapter {
    private Context context;
    
    public ListRifiutiAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.context = context;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = super.getView(position, convertView, parent);
        TextView label = (TextView) row.findViewById(R.id.rifiuto);
        
        String icona = "ic_list_" + getCursor().getString(3);
        int idIcona = Utils.getResId(icona, context, R.drawable.class);
        if (idIcona == -1) {
            icona = getCursor().getString(3);
            idIcona = Utils.getResId(icona, context, R.drawable.class);
        }
        Drawable icon = context.getResources().getDrawable(idIcona);
        label.setCompoundDrawablesWithIntrinsicBounds(icon, null, null,
                                                      null);
        
        return row;
    }
}
